<template>
	<view class="content">
		<input class="inp" @input="onInp" type="text" placeholder="请输入..." />
		<button @click="onTools">点击测试-tools</button>
		<button @click="onUtils">点击测试-utils</button>
		<button @longpress="clipboard($event)">长按复制到剪贴板</button>
		
		<view style="padding:10rpx;background:green;"></view>
		<view class="">{{cont}}</view>
		<button @click="onSaveImg">小程序保存相册</button>
		<tabbar-app></tabbar-app>
	</view>
</template>

<script setup>
	import {
		onLoad
	} from '@dcloudio/uni-app'
	import {
		ref
	} from 'vue'
	import {
		getDistrict,
	} from '../../api/index.js'
	import tools from '../../utils/tools.js'
	import {
		debounce,
		throttle
	} from '../../utils/utils.js'

	let arr = ['a', "b", "c", "d", "e", "f", "g"]
	let date = new Date().getTime()
	let popup = ref()

	const onInp = (e) => {
		console.log('input：', e.target.value);
	}

	const onTools = () => {
		tools.toast('查询中', '', () => {}, {
			image: '../../static/image/6.png'
		})
	}

	const onUtils = throttle(async () => {
		let res = await getDistrict()
	}, 1000)

	const download = () => {
		tools.downloadFile()
	}
	const clipboard = (e) => {
		tools.longpress(e, '剪贴板oo')
	}



	let cont = ref('')
	const onSaveImg = () => {
		console.log('保存');
		uni.downloadFile({
			url: 'https://api.xiaoshengkeji.cn/upload/xiaosheng.xiaoshengkeji.cn/231226/11513784309.png', //仅为示例，并非真实的资源
			success: (res) => {
				if (res.statusCode === 200) {
					console.log('下载成功', res.tempFilePath);
					uni.saveImageToPhotosAlbum({
						filePath: res.tempFilePath,
						success: function(res) {
							// uni.hideLoading();
							// uni.showToast({
							// 	title: "保存成功",
							// 	icon: "none"
							// });
							cont.value = JSON.stringify(res)
							// tools.toast(JSON.stringify(res),5000)
						},
						fail: function(res) {
							cont.value = JSON.stringify(res)
							// tools.toast(JSON.stringify(res),5000)
							// console.log('res', res);
						}
					});
				}
			}
		});
	}
</script>

<style lang="scss" scoped>
	.content {
		width: 100vw;

		.inp {
			border: 1px solid pink;
			height: 80rpx;
			text-align: center;
			padding: 0 25rpx;
			margin: 0 50rpx;
		}
	}

	.popup-content {
		background-color: #fff;
	}
</style>